#ifndef _ADC_H
#define _ADC_H

#include "type.h"
#include "clock.h"

#define ADC_POWERON  (1 << 12)

/* set adc frequency to MHz (max of 13 MHz allowed for LPC17xx) */
#define ADC_FRQ_VALUE           4500000

#define ADC_PRESCALER_VALUE     (((MAIN_FREQUENCY / PCLK_ADC_DIVIDER) / ADC_FRQ_VALUE) -1)

/* adc control register settings */
#define ADC_CHANNEL_0           (1 << 0)
#define ADC_CHANNEL_1           (1 << 1)
#define ADC_CHANNEL_2           (1 << 2)
#define ADC_CHANNEL_3           (1 << 3)
#define ADC_CHANNEL_4           (1 << 4)
#define ADC_CHANNEL_5           (1 << 5)
#define ADC_CHANNEL_6           (1 << 6)
#define ADC_CHANNEL_7           (1 << 7)
#define ADC_PRESCALER           (4 << 8)
#define ADC_OPERATIONAL         (1 << 21)
#define ADC_START_CONVERSION    (1 << 24)
#define ADC_BURST               (1 << 16)
#define ADC_DONE                (1 << 31)
#define ADC_MASK                0x0000FFC0

/* interrupt enable registers */
#define ADC_INTEN0              (1 << 0)

#define ADC_COUNT               1

void adc_irq(void);
void adc_init(void);
uint32_t adc_get(void);

extern volatile uint32_t adc_value[ADC_COUNT];

#endif /* _ADC_H */
